package com.sdtele.tta.operation;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.Task;
import com.sdtele.tta.models.User;

/**
 * 操作类实现：GetUser(json.operation=getUser)
 * 
 * @author XCream
 */
public class OperationSetDeadLine extends Operation {

	@Override
	public JsonResponse handle(JsonRequest jsonRequest) {
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		long taskId = jsonRequest.getJsonObject().get("taskId").getAsLong();
		String deadLineStr = jsonRequest.getJsonObject().get("deadLine").getAsString();
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		java.util.Date ud = new java.util.Date();
		Date deadLine = new java.sql.Date(ud.getTime());
		try {
			deadLine = (Date) sdf.parse(deadLineStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Task task = Dac.getInstance().getTaskbyTaskid(taskId);
		task.setDeadLine(deadLine);
		
		
		
		
		
			if (Dac.getInstance().chgTask(task))

			{
				jres.setStatus(0);
				jres.setMessage("修改成功");
				jres.setEntity(task);
			}

			else {
			jres.setStatus(1);
			jres.setMessage("修改失败");
		}

		return jres;
	}

}
